import axios from 'axios';

import { Post, PostFormat, PostId } from '../models/post';

type PostSummary = {
  postId?: PostId;
  title: string;
  content: string;
  format: PostFormat;
};

export const getPost = (postId: PostId): Promise<Post> => axios.get('/api/post/' + postId).then((resp) => resp.data);

export const getPostList = (): Promise<Post[]> => axios.get('/api/post').then((resp) => resp.data);

export const savePost = (postSummary: PostSummary): Promise<{ postId: number }> =>
  axios.post('/api/post/', postSummary).then((resp) => resp.data);
